#include <iostream>
#include "indexer.h++"
#include "serializer.h++"

int main(int argc, char** argv) {
	if (argc < 2) {
		std::cout << "i need a directory to index ..." << std::endl;
		return 2;
	}

	WritableMappedMemory nodes("TRIE.INDEX");
	WritableMappedMemory rest("INFO.INDEX");
	WritableMappedMemory postings("POSTINGS.INDEX");
	Serializer serializer;
	serializer.set_wordtree_file(&nodes);
	serializer.set_moreinfo_file(&rest);
	serializer.set_documents_file(&rest);
	serializer.set_paths_file(&rest);
	serializer.set_postings_file(&postings);
	
	Indexer indexer(serializer);
	indexer.init();
	indexer.index_dir(std::string(argv[1]));

	indexer.finish_and_serialize();
	std::cout << "finished, now tearing down memory ..." << std::endl;
	return 0;
}
